package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/3/9 9:45
 * @description：https://leetcode-cn.com/problems/smallest-rotation-with-highest-score/
 */
public class 得分最高的最小轮调 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.bestRotation(new int[]{2, 3, 1, 4, 0}));
    }

    class Solution {
        public int bestRotation(int[] nums) {
            int maxScore = 0;
            int len = nums.length;
            int maxK = 0;
            for (int k = 0; k < len; k++) {
                int score = 0;
                for (int i = 0; i < len; i++) {
                    if (nums[(k + i) % len] <= i) {
                        score++;
                    }
                }
                if (score > maxScore) {
                    maxK = k;
                    maxScore = score;
                }
            }
            return maxK;
        }
    }
}
